﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HTTT.Bussiness;
using HTTT.Utilities;
using HTTT.DataAccess;
using HTTT.AD;
using System.Configuration;

namespace HTTT.admin
{
    public partial class RequestListApproved : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CheckPermission();
                LoadData();
            }
        }
        private void CheckPermission()
        {
            if (!Page.User.IsInRole(Constants.ROLE_SUPER_ADMINISTRATOR)
                 && !Page.User.IsInRole(Constants.ROLE_ADMINISTRATOR))
            {
                Response.Redirect("/admin/AccessDenied.aspx");
            }
        }

        private void LoadData()
        {
            //Read all VideoCategory
            HT_RequestBO Bo = new HT_RequestBO();
            rptData.DataSource = Bo.GetAllHT_RequestByStatus(HT_REQUESTSTATUS.APPROVED);
            rptData.DataBind();
        }
        protected void btnAdd_Click(Object sender, EventArgs e)
        {
            Response.Redirect("adduser.aspx");
        }
        protected void btnEdit_Click(Object sender, EventArgs e)
        {
            string EditID = "-1";
            foreach (RepeaterItem ri in rptData.Items)
            {
                CheckBox chk = (CheckBox)ri.FindControl("chkItem");
                if (chk.Checked)
                {
                    EditID = chk.Attributes["value"];
                }
            }
            //Response.Redirect("VideoCategoryModify.aspx?ID=" + EditID);
        }

        protected void btnUnpublish_Click(Object sender, EventArgs e)
        {

        }

        protected void btnPublish_Click(Object sender, EventArgs e)
        {
            // Get request
            string EditID = "-1";
            foreach (RepeaterItem ri in rptData.Items)
            {
                CheckBox chk = (CheckBox)ri.FindControl("chkItem");
                if (chk.Checked)
                {
                    EditID = chk.Attributes["value"];
                }
            }
            Guid TempID;
            Guid.TryParse(EditID, out TempID);
            // Do approve request
            HT_RequestBO RequestBO = new HT_RequestBO();
            HT_AuthenticateInfo AuthenInfo = new HT_AuthenticateInfo(
                                                ConfigurationManager.AppSettings["LDAPDomain"]
                                              , ConfigurationManager.AppSettings["LDAPPath"]
                                              , ConfigurationManager.AppSettings["LDAPUser"]
                                              , ConfigurationManager.AppSettings["LDAPPassword"]);
            ReturnValue<bool> ret = RequestBO.ApproveRequest(TempID, AuthenInfo, Page.User.Identity.Name);
            ClientScript.RegisterStartupScript(this.GetType(), "Message", Common.FormatAlertMsg(ret.Msg), true);
        }

    }
}